<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Cross-profiling (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="Cross-profiling (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="Cross-profiling (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Gcov.html" rel="up" title="Gcov">
<link href="Freestanding-Environments.html" rel="next" title="Freestanding Environments">
<link href="Gcov-Data-Files.html" rel="prev" title="Gcov Data Files">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
kbd.key {font-style: normal}
span:hover a.copiable-link {visibility: visible}
ul.mark-bullet {list-style-type: disc}
-->
</style>


</head>

<body lang="en_US">
<div class="section-level-extent" id="Cross_002dprofiling">
<div class="nav-panel">
<p>
Next: <a href="Freestanding-Environments.html" accesskey="n" rel="next">Profiling and Test Coverage in Freestanding Environments</a>, Previous: <a href="Gcov-Data-Files.html" accesskey="p" rel="prev">Brief Description of <code class="command">gcov</code> Data Files</a>, Up: <a href="Gcov.html" accesskey="u" rel="up"><code class="command">gcov</code>&mdash;a Test Coverage Program</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Data-File-Relocation-to-Support-Cross_002dProfiling"><span>10.5 Data File Relocation to Support Cross-Profiling<a class="copiable-link" href="#Data-File-Relocation-to-Support-Cross_002dProfiling"> &para;</a></span></h3>

<p>Running the program will cause profile output to be generated.  For each
source file compiled with <samp class="option">-fprofile-arcs</samp>, an accompanying <samp class="file">.gcda</samp>
file will be placed in the object file directory. That implicitly requires
running the program on the same system as it was built or having the same
absolute directory structure on the target system. The program will try
to create the needed directory structure, if it is not already present.
</p>
<p>To support cross-profiling, a program compiled with <samp class="option">-fprofile-arcs</samp>
can relocate the data files based on two environment variables:
</p>
<ul class="itemize mark-bullet">
<li>GCOV_PREFIX contains the prefix to add to the absolute paths
in the object file. Prefix can be absolute, or relative.  The
default is no prefix.

</li><li>GCOV_PREFIX_STRIP indicates the how many initial directory names to strip off
the hardwired absolute paths. Default value is 0.

<p><em class="emph">Note:</em> If GCOV_PREFIX_STRIP is set without GCOV_PREFIX is undefined,
 then a relative path is made out of the hardwired absolute paths.
</p></li></ul>

<p>For example, if the object file <samp class="file">/user/build/foo.o</samp> was built with
<samp class="option">-fprofile-arcs</samp>, the final executable will try to create the data file
<samp class="file">/user/build/foo.gcda</samp> when running on the target system.  This will
fail if the corresponding directory does not exist and it is unable to create
it.  This can be overcome by, for example, setting the environment as
&lsquo;<samp class="samp">GCOV_PREFIX=/target/run</samp>&rsquo; and &lsquo;<samp class="samp">GCOV_PREFIX_STRIP=1</samp>&rsquo;.  Such a
setting will name the data file <samp class="file">/target/run/build/foo.gcda</samp>.
</p>
<p>You must move the data files to the expected directory tree in order to
use them for profile directed optimizations (<samp class="option">-fprofile-use</samp>), or to
use the <code class="command">gcov</code> tool.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Freestanding-Environments.html">Profiling and Test Coverage in Freestanding Environments</a>, Previous: <a href="Gcov-Data-Files.html">Brief Description of <code class="command">gcov</code> Data Files</a>, Up: <a href="Gcov.html"><code class="command">gcov</code>&mdash;a Test Coverage Program</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
